<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,反编译,安全," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="本文中提到的方法，思路以及资料，仅供学习交流。  场景介绍分析小米桌面的起因，是由于负责的两个项目，都有在桌面创建快捷方式的需求，两份功能代码基本完全一致，可是，在一款红米2，MIUI7的手机上，A产品可以正常申请权限，创建快捷方式，B产品却不可以。在测试过程中发现，如果把B产品包名修改一下，创建快捷方式的功能就是正常的。由此我们怀疑，在创建快捷方式控制的地方，我们的B产品被拉进了黑名单，不要问">
<meta name="keywords" content="Android,反编译,安全">
<meta property="og:type" content="article">
<meta property="og:title" content="Android反编译－小米桌面逆向过程记录">
<meta property="og:url" content="http://imesong.com/2017/02/04/2017/Android反编译实战-小米桌面的逆向记录/index.html">
<meta property="og:site_name" content="imesong">
<meta property="og:description" content="本文中提到的方法，思路以及资料，仅供学习交流。  场景介绍分析小米桌面的起因，是由于负责的两个项目，都有在桌面创建快捷方式的需求，两份功能代码基本完全一致，可是，在一款红米2，MIUI7的手机上，A产品可以正常申请权限，创建快捷方式，B产品却不可以。在测试过程中发现，如果把B产品包名修改一下，创建快捷方式的功能就是正常的。由此我们怀疑，在创建快捷方式控制的地方，我们的B产品被拉进了黑名单，不要问">
<meta property="og:updated_time" content="2017-04-19T04:53:44.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android反编译－小米桌面逆向过程记录">
<meta name="twitter:description" content="本文中提到的方法，思路以及资料，仅供学习交流。  场景介绍分析小米桌面的起因，是由于负责的两个项目，都有在桌面创建快捷方式的需求，两份功能代码基本完全一致，可是，在一款红米2，MIUI7的手机上，A产品可以正常申请权限，创建快捷方式，B产品却不可以。在测试过程中发现，如果把B产品包名修改一下，创建快捷方式的功能就是正常的。由此我们怀疑，在创建快捷方式控制的地方，我们的B产品被拉进了黑名单，不要问">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://imesong.com/2017/02/04/2017/Android反编译实战-小米桌面的逆向记录/"/>





  <title> Android反编译－小米桌面逆向过程记录 | imesong </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb36183ed65a7652b909d352ab2166";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">imesong</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">我们的征途是星辰大海</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://imesong.com/2017/02/04/2017/Android反编译实战-小米桌面的逆向记录/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="imesong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://s.gravatar.com/avatar/bd2525e0ecc6d8022339c7dce27065c0?s=160">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="imesong">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Android反编译－小米桌面逆向过程记录
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-04T14:57:05+08:00">
                2017-02-04
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index">
                    <span itemprop="name">Android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <blockquote>
<p>本文中提到的方法，思路以及资料，仅供学习交流。</p>
</blockquote>
<h3 id="场景介绍"><a href="#场景介绍" class="headerlink" title="场景介绍"></a>场景介绍</h3><p>分析小米桌面的起因，是由于负责的两个项目，都有在桌面创建快捷方式的需求，两份功能代码基本完全一致，可是，在一款红米2，MIUI7的手机上，A产品可以正常申请权限，创建快捷方式，B产品却不可以。在测试过程中发现，如果把B产品包名修改一下，创建快捷方式的功能就是正常的。由此我们怀疑，在创建快捷方式控制的地方，我们的B产品被拉进了黑名单，不要问我为什么会被拉黑，因为我是无辜的。大致场景就是这个样子。<br><a id="more"></a></p>
<h3 id="创建快捷方式的流程"><a href="#创建快捷方式的流程" class="headerlink" title="创建快捷方式的流程"></a>创建快捷方式的流程</h3><p>关于桌面快捷方式，不了解的可以参考下 <strong>eclipse_xu</strong>的<a href="http://www.jianshu.com/p/dc3d04337d00" target="_blank" rel="external">Android快捷方式解密</a>这篇文章，详细介绍了如何创建快捷方式，创建快捷方式的几种方法。项目已经开源<a href="https://github.com/xuyisheng/ShortcutHelper" target="_blank" rel="external">ShortcutHelper</a>,可以参考。</p>
<p>无论使用何种方法，创建的这个操作，都是通过下面这段代码完成的。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String ACTION_ADD_SHORTCUT = <span class="string">"com.android.launcher.action.INSTALL_SHORTCUT"</span>;</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">addShortcut</span><span class="params">(Context context, Intent actionIntent, String name,                                   <span class="keyword">boolean</span> allowRepeat, Bitmap iconBitmap)</span> </span>&#123;</div><div class="line">    Intent addShortcutIntent = <span class="keyword">new</span> Intent(ACTION_ADD_SHORTCUT);</div><div class="line">    <span class="comment">// 是否允许重复创建</span></div><div class="line">    addShortcutIntent.putExtra(<span class="string">"duplicate"</span>, allowRepeat);</div><div class="line">    <span class="comment">// 快捷方式的标题</span></div><div class="line">    addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);</div><div class="line">    <span class="comment">// 快捷方式的图标</span></div><div class="line">    addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconBitmap);</div><div class="line">    <span class="comment">// 快捷方式的动作</span></div><div class="line">    addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);</div><div class="line">    context.sendBroadcast(addShortcutIntent);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>通过发送广播，交给广播接收者，根据发送者提供的信息，创建快捷方式。</p>
<p>同样是上面的代码，产品A和产品B执行的结果不一样，影响因素只可能是产品的包名了。</p>
<h3 id="验证创建失败原因"><a href="#验证创建失败原因" class="headerlink" title="验证创建失败原因"></a>验证创建失败原因</h3><p>为了确认产品A和B是由于包名不一致，导致快捷方式创建的结果不同，做了如下测试。</p>
<table>
<thead>
<tr>
<th>测试内容</th>
<th>测试结果</th>
</tr>
</thead>
<tbody>
<tr>
<td>A包名修改为B</td>
<td>不可以</td>
</tr>
<tr>
<td>B包名改为A</td>
<td>可以</td>
</tr>
<tr>
<td>A包名改为C</td>
<td>可以</td>
</tr>
<tr>
<td>ShortCutHelperDemo</td>
<td>可以</td>
</tr>
<tr>
<td>ShortCutHelperDemo 改为B</td>
<td>不可以</td>
</tr>
</tbody>
</table>
<p>上面的表格，可以猜测出来，肯定和包名有关。具体有什么关系，要找到 <strong>ACTION_ADD_SHORTCUT</strong> 这个Action的接收者,也就是MIUIHome，拿到其中代码，才能知道。</p>
<h3 id="寻找MIUIHome-APK"><a href="#寻找MIUIHome-APK" class="headerlink" title="寻找MIUIHome.APK"></a>寻找MIUIHome.APK</h3><p>小米的桌面负责创建快捷方式，但我们发现，应用市场上并不能找到最新版或者是MIUI7上的小米桌面App，作为系统级App，小米是没有上线其他市场的。</p>
<p>找一款root的小米手机，到 data/app 目录下，找到 miuihome.apk。然后使用 adb pull 命令，导出到电脑上。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">adb pull data/app/miuihome.apk ~/Desktop/</div></pre></td></tr></table></figure>
<h3 id="反编译apk"><a href="#反编译apk" class="headerlink" title="反编译apk"></a>反编译apk</h3><p>反编译apk的一般过程，这里就不再赘述，可以参考之前的文章<a href="http://www.jianshu.com/c/14422b79096e" target="_blank" rel="external">跟着小强学Android反编译</a></p>
<ol>
<li>解压，拿到 dex 文件</li>
</ol>
<p><strong>解压之后傻眼了啊，根本没有 dex 文件</strong></p>
<p>没有dex，java 代码在哪里执行的呢？总不能全部都直接做在ROM里面吧？从网上下载一个MIUI7的ROM，解压之后也没有发现对应的JAVA代码，第三方APP中之后一个smartHome.apk，看着有点关系（其实没有一点卵用，这个是弯路）。</p>
<p>还是回到手机的目录中，挨个查找。</p>
<h3 id="WTF，没有java代码"><a href="#WTF，没有java代码" class="headerlink" title="WTF，没有java代码"></a>WTF，没有java代码</h3><h3 id="寻找odex"><a href="#寻找odex" class="headerlink" title="寻找odex"></a>寻找odex</h3><h3 id="反编译-odex"><a href="#反编译-odex" class="headerlink" title="反编译 odex"></a>反编译 odex</h3><p>odex 是如何生成的</p>
<p>工具很重要</p>
<h3 id="拿到jar"><a href="#拿到jar" class="headerlink" title="拿到jar"></a>拿到jar</h3><h3 id="寻找关键点"><a href="#寻找关键点" class="headerlink" title="寻找关键点"></a>寻找关键点</h3><h3 id="再深入"><a href="#再深入" class="headerlink" title="再深入"></a>再深入</h3><h3 id="然并卵"><a href="#然并卵" class="headerlink" title="然并卵"></a>然并卵</h3>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag"># Android</a>
          
            <a href="/tags/反编译/" rel="tag"># 反编译</a>
          
            <a href="/tags/安全/" rel="tag"># 安全</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/09/19/2017LearningList/" rel="next" title="2019LearningList">
                <i class="fa fa-chevron-left"></i> 2019LearningList
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/08/12/2016/LinuxShell脚本攻略/" rel="prev" title="LinuxShell脚本攻略">
                LinuxShell脚本攻略 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://s.gravatar.com/avatar/bd2525e0ecc6d8022339c7dce27065c0?s=160"
               alt="imesong" />
          <p class="site-author-name" itemprop="name">imesong</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/imesong" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#场景介绍"><span class="nav-number">1.</span> <span class="nav-text">场景介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建快捷方式的流程"><span class="nav-number">2.</span> <span class="nav-text">创建快捷方式的流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#验证创建失败原因"><span class="nav-number">3.</span> <span class="nav-text">验证创建失败原因</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#寻找MIUIHome-APK"><span class="nav-number">4.</span> <span class="nav-text">寻找MIUIHome.APK</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#反编译apk"><span class="nav-number">5.</span> <span class="nav-text">反编译apk</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#WTF，没有java代码"><span class="nav-number">6.</span> <span class="nav-text">WTF，没有java代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#寻找odex"><span class="nav-number">7.</span> <span class="nav-text">寻找odex</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#反编译-odex"><span class="nav-number">8.</span> <span class="nav-text">反编译 odex</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#拿到jar"><span class="nav-number">9.</span> <span class="nav-text">拿到jar</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#寻找关键点"><span class="nav-number">10.</span> <span class="nav-text">寻找关键点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#再深入"><span class="nav-number">11.</span> <span class="nav-text">再深入</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#然并卵"><span class="nav-number">12.</span> <span class="nav-text">然并卵</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">imesong</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  





  





  






  





  

  

  

  

  

</body>
</html>
